// app.js
const https = require('./utils/https.js')
const user = require('./utils/user.js')

App({
  onLaunch() {
    // 展示本地存储能力
    const logs = wx.getStorageSync('logs') || []
    logs.unshift(Date.now())
    wx.setStorageSync('logs', logs)

    // 登录
    wx.login({
      success: res => {
        // 发送 res.code 到后台换取 openId, sessionKey, unionId
        this.login(res.code)
      }
    })
  },
  globalData: {
    userInfo: null,
    ls: 'dd'
  },
  login(code) {
    const form = {
      code: code
    }
    https.post('/api/login', form).then((res) => {
      // wx.showToast({
      //   title: res.msg,
      //   icon: 'none', // error loading none
      //   mask: true, // 是否显示透明蒙层，防止触摸穿透
      //   duration: 1000
      // })
      if (res.code == 0) {
        user.login(res.data)
      } else {
      }
    })
  }
})
